<template>
  <DataList 
  :cate="cate" 
  :cols="cols"
  :excelHeader="excelHeader"
  skipExcelNumber="2"
  :name="name" />
</template>
<script>
import DataList from "@/components/DataList";
import { getUser } from "@/utils/auth";
import linq from "linq";
import { addJzxqk, deleteJzxqk, updateJzxqk, getJzxqk, bulkAddJzxqk} from "@/api/奖助学情况.js";
import { mkdir } from 'fs';
export default {
  components: {
    DataList
  },
  data() {
    return {
      cate: "A8-8奖助学情况表",
      name:'8.8 奖助学情况',
      excelHeader:{B3:"项目名称(全称)",C3:"项目种类",D3:"奖助范围",E3:"奖助人数",F3:"奖助金额（万元）"},
      cols: [
       
        { label: "项目名称(全称)", prop: "XMMC" },
        { label: "项目种类", prop: "XZ_JZXMZL"},
        { label: "奖助范围", prop: "JZXMFW"},
        { label: "奖助人数", prop: "JZRS"},
        { label: "奖助金额(万元)", prop: "JZJE"}
      ]
    };
  },
  methods: {
    getSummaries(list){
      //
        const sums = [];
         this.cols.forEach((column, index) => {
            sums[index]="";
        });
        sums[6]= "项目数:"+linq.from(list).count("$.XMMC");
        sums[7]= "种类:"+linq.from(list).distinct("$.XZ_JZXMZL").count();
        sums[9]= "人数:"+linq.from(list).sum("$.JZRS");
        sums[10]= "金额:"+linq.from(list).sum("$.JZJE");
       
        return sums;
        },

    async fetchData() {
      var user = getUser();
      var datas = await getJzxqk(user.XXID,user.CJPC);
      return datas;
    },
    check(array,list) {
     return new Promise(async (resolve,reject)=>{
       resolve();
     })
 },
     onadd(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           
      
          console.log(JSON.stringify(temp));
          var model = await addJzxqk(temp);
          resolve(model);
      })
      
    },
    async  bulkAdd(array){
       await  bulkAddJzxqk({Jzxqk:array});
    },
    onupdate(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           
          console.log(JSON.stringify(temp));
          var model = await updateJzxqk(temp);
          resolve(model);
      })
      //
    },
    ondelete(model) {
       var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
        
         await deleteJzxqk(temp);
          resolve();
      })
    }
  }
};
</script>
<style>
</style>